﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ZeroBugBounce.Missive
{
	class RudeTimeoutExecutor
	{
		ThreadStart Work;
		TimeSpan Timeout;
		Thread ExecutionThread;

		public RudeTimeoutExecutor(ThreadStart work, TimeSpan timeout)
		{
			Work = work;
			Timeout = timeout;
		}

		public bool Execute()
		{
			ExecutionThread = new Thread(Work);
			ExecutionThread.Start();
			bool completed = ExecutionThread.Join(Timeout);

			if (!completed)
			{
				ExecutionThread.Abort();
			}

			return completed;
		}
	}
}
